package com.ruoyi.webActivity.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtil;
import com.ruoyi.common.utils.ObjUtil;
import com.ruoyi.common.utils.StrUtil;
import com.ruoyi.manage.cms.domain.*;
import com.ruoyi.manage.cms.domain.vo.HbHqzcVo;
import com.ruoyi.manage.cms.domain.vo.HbNewsVo;
import com.ruoyi.manage.cms.domain.vo.HbZcfgVo;
import com.ruoyi.manage.cms.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 资讯类
 *
 * @author ruoyi
 * @date 2025-07-18
 */
@Api(tags="资讯类控制器")
@RestController
@RequestMapping("/web/information" )
public class webNewsController extends BaseController {
    /**
     * 配置表别名 默认空
     */
    private final static String TABLE_PREFIX=StrUtil.initTableAlias(null);
    @Autowired
    private IHbNewsService iHbNewsService;
    @Autowired
    private IHbZcfgService iHbZcfgService;
    @Autowired
    private IHbHqzcService iHbHqzcService;
    @Autowired
    private IHbCaseService iHbCaseService;
    @Autowired
    private IHePtjsService iHePtjsService;

    @GetMapping("/news/list")
    public TableDataInfo getNewsList(HbNewsVo hbNews, QueryWrapper<HbNews> queryWrapper){
        startPage();
        if(StrUtil.isNotBlank(hbNews.getTitle())){
            queryWrapper.like(TABLE_PREFIX+"title" ,hbNews.getTitle());
        }
        if(StrUtil.isNotBlank(hbNews.getSource())){
            queryWrapper.like(TABLE_PREFIX+"source" ,hbNews.getSource());
        }
        if(hbNews.getIsTop() != null){
            queryWrapper.eq(TABLE_PREFIX+"is_top" ,hbNews.getIsTop());
        }
        if(hbNews.getStatus() != null){
            queryWrapper.eq(TABLE_PREFIX+"status" ,hbNews.getStatus());
        }
        if (ObjUtil.isNotNull(hbNews.getBeginPublishTime()) && ObjUtil.isNotNull(hbNews.getEndPublishTime())){
            queryWrapper.between(TABLE_PREFIX+"publish_time", DateUtil.beginOfDay(hbNews.getBeginPublishTime()),DateUtil.endOfDay(hbNews.getEndPublishTime()));
        }
        queryWrapper.eq("status","2");
        queryWrapper.orderByDesc(TABLE_PREFIX+"create_time");
        List<HbNews> list = iHbNewsService.list(queryWrapper);
        return getDataTable(list);

    }


    /**
     * 获取news详细信息
     */
    @GetMapping(value = "/news/{id}" )
    public AjaxResult getNewsInfo(@PathVariable("id" ) String id) {
        iHbNewsService.update(new UpdateWrapper<HbNews>().eq("id", id).setSql("view_count = view_count + 1"));
        return AjaxResult.success(iHbNewsService.queryGetById(id));
    }

    @GetMapping("/policy/list")
    public TableDataInfo getPolicyList(HbZcfgVo hbZcfg, QueryWrapper<HbZcfg> queryWrapper){
        startPage();
        if(StrUtil.isNotBlank(hbZcfg.getTitle())){
            queryWrapper.like(TABLE_PREFIX+"title" ,hbZcfg.getTitle());
        }
        if (ObjUtil.isNotNull(hbZcfg.getBeginPublishTime()) && ObjUtil.isNotNull(hbZcfg.getEndPublishTime())){
            queryWrapper.between(TABLE_PREFIX+"publish_time", DateUtil.beginOfDay(hbZcfg.getBeginPublishTime()),DateUtil.endOfDay(hbZcfg.getEndPublishTime()));
        }
        if(hbZcfg.getStatus() != null){
            queryWrapper.eq(TABLE_PREFIX+"status" ,hbZcfg.getStatus());
        }
        if(hbZcfg.getIsDeleted() != null){
            queryWrapper.eq(TABLE_PREFIX+"is_deleted" ,hbZcfg.getIsDeleted());
        }
        if(hbZcfg.getIsTop() != null){
            queryWrapper.eq(TABLE_PREFIX+"is_top" ,hbZcfg.getIsTop());
        }
        queryWrapper.eq("status","2");
        queryWrapper.orderByDesc(TABLE_PREFIX+"create_time");
        List<HbZcfg> list = iHbZcfgService.list(queryWrapper);
        return getDataTable(list);

    }

    /**
     * 获取政策法规详细信息
     */
    @GetMapping(value = "/policy/{id}" )
    public AjaxResult getZcfgInfo(@PathVariable("id" ) String id) {
        iHbZcfgService.update(new UpdateWrapper<HbZcfg>().eq("id", id).setSql("view_count = view_count + 1"));
        return AjaxResult.success(iHbZcfgService.queryGetById(id));
    }

    @GetMapping("/policies/list")
    public TableDataInfo getPolicyList(HbHqzcVo hbHqzc, QueryWrapper<HbHqzc> queryWrapper){
        startPage();
        if(StrUtil.isNotBlank(hbHqzc.getTitle())){
            queryWrapper.like(TABLE_PREFIX+"title" ,hbHqzc.getTitle());
        }
        if(StrUtil.isNotBlank(hbHqzc.getArticleType())){
            queryWrapper.eq(TABLE_PREFIX+"article_type" ,hbHqzc.getArticleType());
        }
        if (ObjUtil.isNotNull(hbHqzc.getBeginPublishTime()) && ObjUtil.isNotNull(hbHqzc.getEndPublishTime())){
            queryWrapper.between(TABLE_PREFIX+"publish_time", DateUtil.beginOfDay(hbHqzc.getBeginPublishTime()),DateUtil.endOfDay(hbHqzc.getEndPublishTime()));
        }
        if(hbHqzc.getStatus() != null){
            queryWrapper.eq(TABLE_PREFIX+"status" ,hbHqzc.getStatus());
        }
        if(hbHqzc.getIsDeleted() != null){
            queryWrapper.eq(TABLE_PREFIX+"is_deleted" ,hbHqzc.getIsDeleted());
        }
        if(hbHqzc.getIsTop() != null){
            queryWrapper.eq(TABLE_PREFIX+"is_top" ,hbHqzc.getIsTop());
        }
        queryWrapper.eq("status","2");
        queryWrapper.orderByDesc(TABLE_PREFIX+"create_time");
        List<HbHqzc> list = iHbHqzcService.list(queryWrapper);
        return getDataTable(list);

    }

    /**
     * 获取政策优惠详细信息
     */
    @GetMapping(value = "/policies/{id}" )
    public AjaxResult getPoliciesInfo(@PathVariable("id" ) String id) {
        iHbHqzcService.update(new UpdateWrapper<HbHqzc>().eq("id", id).setSql("view_count = view_count + 1"));
        return AjaxResult.success(iHbHqzcService.queryGetById(id));
    }


    /**
     * 查询case列表
     */
    @ApiOperation(value = "查询case",notes = "case管理")
    @GetMapping("/case/list" )
    public TableDataInfo list(QueryWrapper<HbCase> queryWrapper) {
        startPage();
        List<HbCase> list = iHbCaseService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 查询平台介绍列表
     */
    @ApiOperation(value = "查询平台介绍",notes = "平台介绍管理")
    @GetMapping("/plat/list" )
    public TableDataInfo platform(QueryWrapper<HePtjs> queryWrapper) {
        startPage();
        List<HePtjs> list = iHePtjsService.list(queryWrapper);
        return getDataTable(list);
    }
}
